class MachineUpgrade extends eui.Component{
	constructor(){
		super();
		this.skinName="skins.scene.MachineUpgradeSkin";
		this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAdded, this );
		this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoved, this);
	}
	private onClose(evt:egret.TouchEvent){
		this.hide();
	}
	public hide(){
		DisplayController.instance().removeFromAlert(GameConst.GrayMask);
		DisplayController.instance().removeFromAlert(this);
	}
	private onProduce(evt:egret.TouchEvent){
		this.hide();
		window["__upgradeMachine"](this.curMachine.machineId);
	}
	private onAdded(evt:egret.Event){
		this.img_ok.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onProduce, this);
		this.img_close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
	}

	private onRemoved(evt:egret.Event){
		this.img_ok.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onProduce, this);
		this.img_close.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
	}
	private curMachine;
	private nextConfig;
	public show(machineId){
		// this.curMachine = GuildMgr.getInstance().machines[machineId];
		// this.nextConfig = GuildMgr.getInstance().machineConfig[this.curMachine.level+1];
		// if( !DisplayController.instance().stage) return;
		DisplayController.instance().addToAlert(GameConst.GrayMask);
		DisplayController.instance().addToAlert(this);
		this.updateDisplay();
	}
	private updateDisplay(){
		// var unlocks = GuildMgr.getInstance().getUnlockProductdByLevel(this.curMachine.level+1);
		// while( this.container_product.numElements){
		// 	FuckItem.recycle(<FuckItem>this.container_product.removeChildAt(0));
		// }
		// var len = unlocks.length;
		// var item:FuckItem;
		// for(var i = 0; i < len; i++){
		// 	item = FuckItem.gain();
		// 	item.x = 80 * i;
		// 	item.y = 0;
		// 	this.container_product.addChild(item);
		// 	item.setData(unlocks[i].goodsId,2);
		// 	this["lab_name_"+i].text = item.goodInfo.name;
		// 	this["lab_name_"+i].visible = true;
		// }
		// for( ;i<4;i++){
		// 	this["lab_name_"+i].visible = false;
		// }
		// var otherMsg1:string = "来源：家族升级解锁，退出家族后消失。";
		// var otherMsg2:string = "来源：购买解锁，退出家族后保留。";
		// this.lab_content.text = "万能制造机-"+this.curMachine.machineId+"号机	LV."+this.curMachine.level+"\r"+
		// 	(this.curMachine.machineId<4?otherMsg1:otherMsg2);
		// this.lab_content_1.text = "消耗"+this.nextConfig.contribution+"贡献度";
	}

	public img_close:eui.Image;
	public img_ok:eui.Image;
	public lab_content:eui.Label;
	public lab_content_1:eui.Label;
	public lab_name_0:eui.Label;
	public lab_name_1:eui.Label;
	public lab_name_2:eui.Label;
	public lab_name_3:eui.Label;
	public container_product:eui.Group;
	public partAdded(name:string, instance:any){
		super.partAdded(name, instance);
		if(name == "img_close"){
			this.img_close=instance;
		}else if(name == "img_ok"){
			this.img_ok=instance;
		}else if(name == "lab_content"){
			this.lab_content=instance;
		}else if(name == "lab_content_1"){
			this.lab_content_1=instance;
		}else if(name == "lab_name_0"){
			this.lab_name_0=instance;
		}else if(name == "lab_name_1"){
			this.lab_name_1=instance;
		}else if(name == "lab_name_2"){
			this.lab_name_2=instance;
		}else if(name == "lab_name_3"){
			this.lab_name_3=instance;
		}else if(name == "container_product"){
			this.container_product=instance;
		}
	}
	public childrenCreated(){
		super.childrenCreated();
		//todo
	}

	public measure() {
		super.measure();
		this.x = GameConst.StageW - this.measuredWidth >> 1;
		this.y = GameConst.StageH - this.measuredHeight >> 1;
	}

	private static _instance:MachineUpgrade;
	public static getInstance():MachineUpgrade{
		if(MachineUpgrade._instance == null){
			MachineUpgrade._instance = new MachineUpgrade();
		}
		return MachineUpgrade._instance;
	}
}